public class NameRepository implements Container {
    private String[] names = { "a", "b", "c", "d", "e" };
    private Iterator iterator;

    @Override
    public Iterator getIterator() {
        if (iterator == null) {
            iterator = new NameIterator();
        }
        return iterator;
    }

    public class NameIterator implements Iterator {
        private int index;

        @Override
        public boolean hasNext() {
            if (index < names.length) {
                return true;
            }
            return false;
        }

        @Override
        public Object next() {
            if (hasNext()) {
                return names[index++];//先取再移动索引
            }
            return null;
        }
    }
}
